<html>
<head>
<title>地图.py</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.s0 { color: #cc7832;}
.s1 { color: #a9b7c6;}
.s2 { color: #6a8759;}
.s3 { color: #808080;}
.s4 { color: #629755; font-style: italic;}
.s5 { color: #6897bb;}
</style>
</head>
<body bgcolor="#2b2b2b">
<table CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#606060" >
<tr><td><center>
<font face="Arial, Helvetica" color="#000000">
地图.py</font>
</center></td></tr></table>
<pre><span class="s0">import </span><span class="s1">tkinter </span><span class="s0">as </span><span class="s1">tk</span>
<span class="s0">from </span><span class="s1">PIL </span><span class="s0">import </span><span class="s1">Image</span><span class="s0">, </span><span class="s1">ImageTk</span>
<span class="s0">from </span><span class="s1">tkinter </span><span class="s0">import </span><span class="s1">messagebox</span>

<span class="s0">class </span><span class="s1">CultivationInterface:</span>
    <span class="s0">def </span><span class="s1">__init__(self):</span>
        <span class="s1">self.root = tk.Tk()</span>
        <span class="s1">self.root.title(</span><span class="s2">&quot;修仙界面 v4.1&quot;</span><span class="s1">)</span>
        <span class="s1">self.root.geometry(</span><span class="s2">&quot;1060x708&quot;</span><span class="s1">)</span>
        <span class="s1">self.root.resizable(</span><span class="s0">False, False</span><span class="s1">)</span>

        <span class="s3"># 初始化背景图</span>
        <span class="s1">self.setup_background()</span>

        <span class="s3"># 初始化界面元素</span>
        <span class="s1">self.setup_character()</span>
        <span class="s1">self.setup_map()</span>
        <span class="s1">self.setup_status_panel()</span>

        <span class="s1">self.root.mainloop()</span>

    <span class="s0">def </span><span class="s1">setup_background(self):</span>
        <span class="s4">&quot;&quot;&quot;设置全屏背景图&quot;&quot;&quot;</span>
        <span class="s3"># 加载并调整背景图大小</span>
        <span class="s1">background_image = Image.open(</span><span class="s2">&quot;F:/python2048/images/大背景.jpg&quot;</span><span class="s1">)</span>
        <span class="s1">background_image = background_image.resize((</span><span class="s5">1060</span><span class="s0">, </span><span class="s5">708</span><span class="s1">)</span><span class="s0">, </span><span class="s1">Image.Resampling.LANCZOS)</span>
        <span class="s1">self.background_photo = ImageTk.PhotoImage(background_image)</span>

        <span class="s3"># 创建用于显示背景图片的Label</span>
        <span class="s1">self.background_label = tk.Label(self.root</span><span class="s0">, </span><span class="s1">image=self.background_photo)</span>
        <span class="s1">self.background_label.place(x=</span><span class="s5">0</span><span class="s0">, </span><span class="s1">y=</span><span class="s5">0</span><span class="s0">, </span><span class="s1">relwidth=</span><span class="s5">1</span><span class="s0">, </span><span class="s1">relheight=</span><span class="s5">1</span><span class="s1">)</span>

    <span class="s0">def </span><span class="s1">setup_character(self):</span>
        <span class="s4">&quot;&quot;&quot;左侧人物立绘系统（精确高度控制）&quot;&quot;&quot;</span>
        <span class="s3"># 创建左侧框架</span>
        <span class="s1">left_frame = tk.Frame(self.root</span><span class="s0">, </span><span class="s1">width=</span><span class="s5">360</span><span class="s0">, </span><span class="s1">height=</span><span class="s5">708</span><span class="s1">)</span>
        <span class="s1">left_frame.place(x=</span><span class="s5">0</span><span class="s0">, </span><span class="s1">y=</span><span class="s5">0</span><span class="s1">)</span>

        <span class="s3"># 加载并调整人物立绘图像大小</span>
        <span class="s1">img = Image.open(</span><span class="s2">&quot;F:/python2048/男主角1.jpg&quot;</span><span class="s1">)</span>
        <span class="s1">max_width = </span><span class="s5">280  </span><span class="s3"># 人物立绘的最大宽度</span>
        <span class="s1">max_height = </span><span class="s5">440  </span><span class="s3"># 保留底部空间</span>
        <span class="s1">ratio = min(max_width / img.width</span><span class="s0">, </span><span class="s1">max_height / img.height)</span>
        <span class="s1">new_size = (int(img.width * ratio)</span><span class="s0">, </span><span class="s1">int(img.height * ratio))</span>
        <span class="s1">img = img.resize(new_size</span><span class="s0">, </span><span class="s1">Image.Resampling.LANCZOS)</span>
        <span class="s1">self.char_img = ImageTk.PhotoImage(img)</span>

        <span class="s3"># 创建Canvas并显示人物立绘</span>
        <span class="s1">canvas = tk.Canvas(left_frame</span><span class="s0">, </span><span class="s1">width=max_width</span><span class="s0">, </span><span class="s1">height=max_height</span><span class="s0">, </span><span class="s1">highlightthickness=</span><span class="s5">0</span><span class="s1">)</span>
        <span class="s1">canvas.pack(side=</span><span class="s2">&quot;bottom&quot;</span><span class="s0">, </span><span class="s1">pady=</span><span class="s5">20</span><span class="s1">)</span>
        <span class="s1">canvas.create_image(max_width // </span><span class="s5">2</span><span class="s0">, </span><span class="s1">max_height</span><span class="s0">, </span><span class="s1">image=self.char_img</span><span class="s0">, </span><span class="s1">anchor=</span><span class="s2">&quot;s&quot;</span><span class="s1">)</span>

    <span class="s0">def </span><span class="s1">setup_map(self):</span>
        <span class="s4">&quot;&quot;&quot;中间地图系统（带精确边距和可点击的位置）&quot;&quot;&quot;</span>
        <span class="s3"># 创建中间框架</span>
        <span class="s1">center_frame = tk.Frame(self.root</span><span class="s0">, </span><span class="s1">width=</span><span class="s5">560</span><span class="s0">, </span><span class="s1">height=</span><span class="s5">708</span><span class="s1">)</span>
        <span class="s1">center_frame.place(x=</span><span class="s5">350</span><span class="s0">, </span><span class="s1">y=</span><span class="s5">0</span><span class="s1">)</span>

        <span class="s3"># 加载并调整地图图像大小</span>
        <span class="s1">img = Image.open(</span><span class="s2">&quot;F:/python2048/地图.jpg&quot;</span><span class="s1">)</span>
        <span class="s1">img.thumbnail((</span><span class="s5">500</span><span class="s0">, </span><span class="s5">650</span><span class="s1">))  </span><span class="s3"># 限制最大尺寸</span>
        <span class="s1">self.map_img = ImageTk.PhotoImage(img)</span>

        <span class="s3"># 创建Canvas并显示地图</span>
        <span class="s1">self.map_canvas = tk.Canvas(center_frame</span><span class="s0">, </span><span class="s1">width=self.map_img.width()</span><span class="s0">, </span><span class="s1">height=self.map_img.height()</span><span class="s0">, </span><span class="s1">highlightthickness=</span><span class="s5">0</span><span class="s1">)</span>
        <span class="s1">self.map_canvas.pack(expand=</span><span class="s0">True</span><span class="s1">)</span>
        <span class="s1">self.map_canvas.create_image(</span><span class="s5">0</span><span class="s0">, </span><span class="s5">0</span><span class="s0">, </span><span class="s1">anchor=</span><span class="s2">&quot;nw&quot;</span><span class="s0">, </span><span class="s1">image=self.map_img)</span>

        <span class="s3"># 添加可点击的位置</span>
        <span class="s1">locations = [</span>
            <span class="s1">(</span><span class="s2">&quot;杨家口&quot;</span><span class="s0">, </span><span class="s5">114</span><span class="s0">, </span><span class="s5">239</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;苍灵峰&quot;</span><span class="s0">, </span><span class="s5">330</span><span class="s0">, </span><span class="s5">140</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;天玄阁&quot;</span><span class="s0">, </span><span class="s5">270</span><span class="s0">, </span><span class="s5">110</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;书阁&quot;</span><span class="s0">, </span><span class="s5">220</span><span class="s0">, </span><span class="s5">190</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;逍遥门&quot;</span><span class="s0">, </span><span class="s5">220</span><span class="s0">, </span><span class="s5">297</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;白家寨子&quot;</span><span class="s0">, </span><span class="s5">265</span><span class="s0">, </span><span class="s5">235</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;黄鹤楼&quot;</span><span class="s0">, </span><span class="s5">225</span><span class="s0">, </span><span class="s5">145</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;灵河宗&quot;</span><span class="s0">, </span><span class="s5">300</span><span class="s0">, </span><span class="s5">360</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;轩村&quot;</span><span class="s0">, </span><span class="s5">249</span><span class="s0">, </span><span class="s5">485</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;左家城&quot;</span><span class="s0">, </span><span class="s5">215</span><span class="s0">, </span><span class="s5">389</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;两仪镇&quot;</span><span class="s0">, </span><span class="s5">81</span><span class="s0">, </span><span class="s5">370</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;丹阁&quot;</span><span class="s0">, </span><span class="s5">61</span><span class="s0">, </span><span class="s5">335</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;木灵宗&quot;</span><span class="s0">, </span><span class="s5">321</span><span class="s0">, </span><span class="s5">285</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;渔村&quot;</span><span class="s0">, </span><span class="s5">341</span><span class="s0">, </span><span class="s5">205</span><span class="s1">)</span>
        <span class="s1">]</span>

        <span class="s0">for </span><span class="s1">name</span><span class="s0">, </span><span class="s1">x</span><span class="s0">, </span><span class="s1">y </span><span class="s0">in </span><span class="s1">locations:</span>
            <span class="s1">self.map_canvas.create_oval(x - </span><span class="s5">5</span><span class="s0">, </span><span class="s1">y - </span><span class="s5">5</span><span class="s0">, </span><span class="s1">x + </span><span class="s5">5</span><span class="s0">, </span><span class="s1">y + </span><span class="s5">5</span><span class="s0">, </span><span class="s1">fill=</span><span class="s2">&quot;red&quot;</span><span class="s0">, </span><span class="s1">tags=name)</span>
            <span class="s1">self.map_canvas.tag_bind(name</span><span class="s0">, </span><span class="s2">&quot;&lt;Button-1&gt;&quot;</span><span class="s0">, lambda </span><span class="s1">e</span><span class="s0">, </span><span class="s1">n=name: self.location_click(n))</span>

    <span class="s0">def </span><span class="s1">location_click(self</span><span class="s0">, </span><span class="s1">name):</span>
        <span class="s1">messagebox.showinfo(</span><span class="s2">&quot;位置&quot;</span><span class="s0">, </span><span class="s2">f&quot;你进入了</span><span class="s0">{</span><span class="s1">name</span><span class="s0">}</span><span class="s2">!&quot;</span><span class="s1">)</span>

    <span class="s0">def </span><span class="s1">setup_status_panel(self):</span>
        <span class="s4">&quot;&quot;&quot;右侧状态面板（显式按钮布局）&quot;&quot;&quot;</span>
        <span class="s3"># 创建右侧框架</span>
        <span class="s1">right_frame = tk.Frame(self.root</span><span class="s0">, </span><span class="s1">width=</span><span class="s5">150</span><span class="s0">, </span><span class="s1">height=</span><span class="s5">708</span><span class="s1">)</span>
        <span class="s1">right_frame.place(x=</span><span class="s5">910</span><span class="s0">, </span><span class="s1">y=</span><span class="s5">0</span><span class="s1">)</span>

        <span class="s3"># 状态数据区</span>
        <span class="s1">data_frame = tk.Frame(right_frame</span><span class="s0">, </span><span class="s1">padx=</span><span class="s5">5</span><span class="s0">, </span><span class="s1">pady=</span><span class="s5">5</span><span class="s0">, </span><span class="s1">bg=</span><span class="s2">&quot;#000000&quot;</span><span class="s1">)</span>
        <span class="s1">data_frame.pack(fill=</span><span class="s2">&quot;x&quot;</span><span class="s1">)</span>

        <span class="s1">status_items = [</span>
            <span class="s1">(</span><span class="s2">&quot;境界&quot;</span><span class="s0">, </span><span class="s2">&quot;金丹后期&quot;</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;修为&quot;</span><span class="s0">, </span><span class="s2">&quot;■■■■□ 80%&quot;</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;气血&quot;</span><span class="s0">, </span><span class="s2">&quot;12800/15000&quot;</span><span class="s1">)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;真气&quot;</span><span class="s0">, </span><span class="s2">&quot;8800/10000&quot;</span><span class="s1">)</span>
        <span class="s1">]</span>

        <span class="s0">for </span><span class="s1">text</span><span class="s0">, </span><span class="s1">value </span><span class="s0">in </span><span class="s1">status_items:</span>
            <span class="s1">row = tk.Frame(data_frame</span><span class="s0">, </span><span class="s1">bg=</span><span class="s2">&quot;#000000&quot;</span><span class="s1">)</span>
            <span class="s1">row.pack(fill=</span><span class="s2">&quot;x&quot;</span><span class="s0">, </span><span class="s1">pady=</span><span class="s5">5</span><span class="s1">)</span>

            <span class="s1">tk.Label(row</span><span class="s0">, </span><span class="s1">text=text</span><span class="s0">, </span><span class="s1">font=(</span><span class="s2">&quot;微软雅黑&quot;</span><span class="s0">, </span><span class="s5">11</span><span class="s1">)</span><span class="s0">, </span><span class="s1">fg=</span><span class="s2">&quot;#AAAAAA&quot;</span><span class="s0">, </span><span class="s1">bg=</span><span class="s2">&quot;#000000&quot;</span><span class="s0">, </span><span class="s1">width=</span><span class="s5">6</span><span class="s0">, </span><span class="s1">anchor=</span><span class="s2">&quot;e&quot;</span><span class="s1">).pack(side=</span><span class="s2">&quot;left&quot;</span><span class="s1">)</span>
            <span class="s1">tk.Label(row</span><span class="s0">, </span><span class="s1">text=value</span><span class="s0">, </span><span class="s1">font=(</span><span class="s2">&quot;微软雅黑&quot;</span><span class="s0">, </span><span class="s5">11</span><span class="s0">, </span><span class="s2">&quot;bold&quot;</span><span class="s1">)</span><span class="s0">, </span><span class="s1">fg=</span><span class="s2">&quot;#FFFFFF&quot;</span><span class="s0">, </span><span class="s1">bg=</span><span class="s2">&quot;#000000&quot;</span><span class="s1">).pack(side=</span><span class="s2">&quot;left&quot;</span><span class="s1">)</span>

        <span class="s1">btn_frame = tk.Frame(right_frame</span><span class="s0">, </span><span class="s1">padx=</span><span class="s5">5</span><span class="s0">, </span><span class="s1">pady=</span><span class="s5">10</span><span class="s0">, </span><span class="s1">bg=</span><span class="s2">&quot;#000000&quot;</span><span class="s1">)  </span><span class="s3"># 设置按钮区背景为黑色</span>
        <span class="s1">btn_frame.pack(fill=</span><span class="s2">&quot;both&quot;</span><span class="s0">, </span><span class="s1">expand=</span><span class="s0">True</span><span class="s1">)</span>

        <span class="s1">buttons = [</span>
            <span class="s1">(</span><span class="s2">&quot;修 炼&quot;</span><span class="s0">, </span><span class="s2">&quot;#4CAF50&quot;</span><span class="s0">, </span><span class="s1">self.cultivation)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;炼 丹&quot;</span><span class="s0">, </span><span class="s2">&quot;#FF9800&quot;</span><span class="s0">, </span><span class="s1">self.alchemy)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;炼 器&quot;</span><span class="s0">, </span><span class="s2">&quot;#2196F3&quot;</span><span class="s0">, </span><span class="s1">self.forging)</span><span class="s0">,</span>
            <span class="s1">(</span><span class="s2">&quot;秘 境&quot;</span><span class="s0">, </span><span class="s2">&quot;#E91E63&quot;</span><span class="s0">, </span><span class="s1">self.secret_realm)</span>
        <span class="s1">]</span>

        <span class="s0">for </span><span class="s1">text</span><span class="s0">, </span><span class="s1">color</span><span class="s0">, </span><span class="s1">command </span><span class="s0">in </span><span class="s1">buttons:</span>
            <span class="s1">btn = tk.Button(btn_frame</span><span class="s0">, </span><span class="s1">text=text</span><span class="s0">, </span><span class="s1">font=(</span><span class="s2">&quot;微软雅黑&quot;</span><span class="s0">, </span><span class="s5">14</span><span class="s1">)</span><span class="s0">, </span><span class="s1">bg=color</span><span class="s0">, </span><span class="s1">fg=</span><span class="s2">&quot;white&quot;</span><span class="s0">, </span><span class="s1">height=</span><span class="s5">2</span><span class="s0">, </span><span class="s1">relief=</span><span class="s2">&quot;raised&quot;</span><span class="s0">, </span><span class="s1">borderwidth=</span><span class="s5">3</span><span class="s0">, </span><span class="s1">command=command)</span>
            <span class="s1">btn.pack(fill=</span><span class="s2">&quot;x&quot;</span><span class="s0">, </span><span class="s1">pady=</span><span class="s5">5</span><span class="s1">)</span>

    <span class="s0">def </span><span class="s1">cultivation(self):</span>
        <span class="s1">messagebox.showinfo(</span><span class="s2">&quot;修炼&quot;</span><span class="s0">, </span><span class="s2">&quot;你开始了闭关修炼，修为有所提升！&quot;</span><span class="s1">)</span>

    <span class="s0">def </span><span class="s1">alchemy(self):</span>
        <span class="s1">messagebox.showinfo(</span><span class="s2">&quot;炼丹&quot;</span><span class="s0">, </span><span class="s2">&quot;你开始炼制丹药，获得了一些珍贵的丹药！&quot;</span><span class="s1">)</span>

    <span class="s0">def </span><span class="s1">forging(self):</span>
        <span class="s1">messagebox.showinfo(</span><span class="s2">&quot;炼器&quot;</span><span class="s0">, </span><span class="s2">&quot;你开始锻造法器，打造出了一件不错的法器！&quot;</span><span class="s1">)</span>

    <span class="s0">def </span><span class="s1">secret_realm(self):</span>
        <span class="s1">messagebox.showinfo(</span><span class="s2">&quot;秘境&quot;</span><span class="s0">, </span><span class="s2">&quot;你进入了一处神秘的秘境，发现了许多宝藏！&quot;</span><span class="s1">)</span>

<span class="s0">if </span><span class="s1">__name__ == </span><span class="s2">&quot;__main__&quot;</span><span class="s1">:</span>
    <span class="s1">app = CultivationInterface()</span>

</pre>
</body>
</html>